package org.zfes.snowier.common.monitor.http.response;

import java.io.InputStream;
import java.io.Serializable;
import java.util.function.Consumer;

public class StreamResponse implements Serializable{
			
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	    private InputStream inputStream;
	    private int statusCode;
	    private long length = 0;

	    private String error;
	    
	    public StreamResponse(int statusCode)  {
		       this.statusCode=statusCode;
		}
	    
	    public StreamResponse(InputStream inputStream, int statusCode)  {
	       this.inputStream=inputStream;
	       this.statusCode=statusCode;
	    }

		public InputStream getInputStream() {
			return inputStream;
		}

		public StreamResponse setInputStream(InputStream inputStream) {
			this.inputStream = inputStream;
			return this;
		}

		public int getStatusCode() {
			return statusCode;
		}

		public StreamResponse setStatusCode(int statusCode) {
			this.statusCode = statusCode;
			return this;
		}

		public long getLength() {
			return length;
		}

		public StreamResponse setLength(long length) {
			this.length = length;
			return this;
		}
		
		
		public String getError() {
			return error;
		}

		public StreamResponse setError(String error) {
			this.error = error;
			return this;
		}
		

		public boolean isok() {
	        return 200==statusCode;
	    }
		
		public <T> void isok(Consumer<? super InputStream> consumer) {
	        if (200==statusCode) {
	        	 consumer.accept(inputStream);
	        }
	    }
		
		
		 public StreamResponse orElse(Consumer<? super StreamResponse> consumer) {
			 if (200!=statusCode) {
	        	 consumer.accept(this);
	        }
			 return this;
		 }
		 public  StreamResponse orElseThrow(Exception e)  {
			 try {
				throw e;
			} catch (Exception e1) {
				
			}
			 return this;
		 }
		 

}
